package com.mall.user.controller;

import com.central.common.model.Result;
import com.mall.entity.Permission;
import com.mall.user.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;


    @GetMapping("/all")
    public Result getAllPermission() {
        List<Permission> permissionList = permissionService.getAllPermission();
        if (permissionList != null) {
            return Result.succeed(permissionList,"查询权限列表成功");
        }
        return Result.failed("查询权限列表失败");
    }

    @GetMapping("/getPermissionMenu")
    public Result getPermissionMenu() {
        List<Permission> permissionList = permissionService.slectPermissionMenu();
        if (permissionList != null) {
            return Result.succeed(permissionList,"查询权限菜单成功");
        }
        return Result.failed("查询权限菜单失败");
    }

    @GetMapping("/getPermissionByMenuId")
    public Result getPermissionByMenuId(@RequestParam("menuId") Integer menuId,@RequestParam("roleId") Integer roleId) {
        List<Permission> permissionList = permissionService.slectPermissionByMenuId(menuId,roleId);
        if (permissionList != null) {
            return Result.succeed(permissionList,"查询权限成功");
        }
        return Result.failed("查询权限失败");
    }

}
